package servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.entity.Psicologo;

/**
 * Servlet implementation class ValidaUsuarioServelet
 */
@WebServlet("/validaUsuario")
public class ValidaUsuarioServlet extends ServletBase {
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		String login = request.getParameter("login");
		String senha = request.getParameter("senha");
		
		RequestDispatcher d = null;
		
		Psicologo psicologoAutenticado = factoryService.psicologoService.verificaPsicologo(login,senha);
		if (psicologoAutenticado != null )
		{
			HttpSession session = request.getSession();
			session.setAttribute("psicologo", psicologoAutenticado);
			
			d = request.getRequestDispatcher("/index.jsp");
			d.forward(request, response);	
		}
		else
		{
			d = request.getRequestDispatcher("/login.jsp");
			d.forward(request, response);
		}
	}

}
